﻿using Wizard.Runtime;
using Wizard.Source;

namespace Wizard.Statements
{
    using Wizard.Runtime;

    [Statement("For loop Statement")]
    internal class For : Statement
    {
        [Variable] public int LoopVariable;
        [Field] public int From;
        [Field] public int To;
        [Block("for main Block")] private IBlockSource MainBlock;

        public override void OnRun(IStatementArgs args, RunArgs runArgs)
        {
            LoopVariable = From;
            if (LoopVariable <= To)
            {
                runArgs.Sub = MainBlock;
                runArgs.RunResult = RunResult.GoSub;
            }
        }

        public override void OnSubComplete(IStatementArgs args, SubCompleteArgs subCompleteArgs)
        {
            LoopVariable += 1;
            if (LoopVariable <= To)
            {
                subCompleteArgs.Sub = MainBlock;
                subCompleteArgs.SubCompleteResult = SubCompleteResult.GoSub;
            }
        }
        
        //public override void LeaveForward(StatementArgs args, LeaveForwardArgs forwardArgs)
        //{
        //}
    }
}